# 实现单向循环链表队列
# 定义节点类：
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None


class LinkedQueue:
    def __init__(self):
        self.front = None
        self.rear = None

    def isEmpty(self):
        if self.front == None and self.rear == None:
            return True
        else:
            return False

    def push(self, value):
        node = Node(value)
        if self.isEmpty():
            self.front = node
            self.rear = node
        else:
            temp = self.rear
            temp.next = node
            self.rear = node
            self.rear.next = self.front

    def pop(self):
        if self.isEmpty():
            return None
        else:
            if self.front == self.rear:
                temp = self.front
                self.front = None
                self.rear = None
                return temp.value
            else:
                temp = self.front
                self.front = self.front.next
                self.rear.next = self.front
                return temp.value


if __name__ == "__main__":
    lq = LinkedQueue()
    if lq.isEmpty():
        print("此链式队列为空！")
    else:
        print("此链式队列不为空！")
    print("开始进队：")
    i = 1
    while i <= 5:
        lq.push(i)
        print(lq.rear.value, end=" ")
        i += 1
    print()
    print("开始出队：")
    while not lq.isEmpty():
        print(lq.pop(), end=" ")
    print()

    # 自己完成下面的题目：
    # 作业：
    # 定义出队的类方法，在主函数中测试一下。进队：1 2 3 4 5  出队：1 2 3 4 5
    # 提交：代码（手写push(),pop()里面的逻辑代码，拍照保存在一起） 截图：运行截图  作业评分表（作业5：单向循环链表队列）
